<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class GoodsCard extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $exists = $this->hasTable('goods_card');
        if (!$exists) {
            $table = $this->table('goods_card', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci', 'comment' => '商品卡券', 'id' => 'id', 'signed' => true, 'primary_key' => ['id']]);
            $table->addColumn('subscript', 'string', ['limit' => 20, 'null' => true, 'signed' => true, 'comment' => '角标',])
                ->addColumn('price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => false, 'default' => 0, 'signed' => true, 'comment' => '面值（元）',])
                ->addColumn('intro', 'string', ['limit' => 255, 'null' => false, 'default' => null, 'signed' => true, 'comment' => '使用介绍',])
                ->addColumn('validity', 'integer', ['limit' => MysqlAdapter::INT_BIG, 'null' => true, 'signed' => true, 'comment' => '有效期',])
                ->addColumn('limit_price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => 0, 'signed' => true, 'comment' => '限制金额',])
                ->addColumn('limit', 'boolean', ['null' => true, 'default' => 1, 'signed' => true, 'comment' => '限制',])
                ->addColumn('limit_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => true, 'signed' => true, 'comment' => '限制ID',])
                ->addColumn('card_code', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'signed' => true, 'comment' => '卡券码',])
                ->addColumn('code_status', 'boolean', ['null' => true, 'default' => 0, 'signed' => true, 'comment' => '码状态',])
                ->addColumn('quantity', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'signed' => true, 'comment' => '可领取数',])
                ->addColumn('weigh', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'signed' => true, 'comment' => '权重',])
                ->addColumn('type', 'boolean', ['null' => false, 'default' => 1, 'signed' => true, 'comment' => '类型',])
                ->addColumn('status', 'boolean', ['null' => false, 'default' => 1, 'signed' => true, 'comment' => '状态',])
                ->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_BIG, 'null' => true, 'signed' => true, 'comment' => '创建时间',])
                ->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_BIG, 'null' => true, 'signed' => true, 'comment' => '更新时间',])
                ->create();
        }
    }
}
